package com.polytech.diploma.OracleStat;

public class SelectStatData {
	protected String sqlText;
	protected int count;	
	/**
	 * Memory statistics
	 */
	protected int runtimeMemory;	/*Fixed amount of memory required during the execution of the child cursor*/
	protected int persistentMemory;	/*Fixed amount of memory used for the lifetime of the child cursor (in bytes)*/
	/**
	 * IO statistics
	 */
	protected int diskReads;		/*Number of disk reads for this child cursor*/
	protected int bufferGets;		/*Number of buffer gets for this child cursor*/
	protected int userIOWaitTime;	/*User I/O Wait Time (in microseconds)*/	
	/**
	 * General cost
	 */
	protected int rowsProcessed;	/*Total number of rows the parsed SQL statement returns*/
	protected int optimizerCost;	/*Cost of this query given by the optimizer*/
	/**
	 * Query duration
	 */
	protected int elapsedTime;		/*Elapsed time (in microseconds) used by this cursor for parsing, executing, and fetching*/
	
	public SelectStatData (String sqlQuery)
	{
		this.sqlText = sqlQuery;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((sqlText == null) ? 0 : sqlText.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SelectStatData other = (SelectStatData) obj;
		if (sqlText == null) {
			if (other.sqlText != null)
				return false;
		} else if (sqlText.equals(other.sqlText))
			{
			/**
			 * Accumulate query statistics
			 */
			this.bufferGets+=other.bufferGets;
			this.count++;
			this.diskReads+=other.diskReads;
			this.elapsedTime+=other.elapsedTime;
			this.optimizerCost+=other.optimizerCost;
			this.persistentMemory+=other.persistentMemory;
			this.rowsProcessed+=other.rowsProcessed;
			this.runtimeMemory+=other.runtimeMemory;
			this.userIOWaitTime+=other.userIOWaitTime;

			return true;
			}
		return false;
	}
	
}
